const WebSocket = require('ws');
const {WebSocketServer} = require('ws');

const wss = new WebSocketServer({ port: 1271 });

wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(data, isBinary) {
        wss.clients.forEach(function each(client) {
            if (client.readyState === WebSocket.OPEN) {
                client.send(data, { binary: isBinary });
            }
        });
    });
    ws.on('open', function open() {
        console.log('链接');
    });
});
wss.on('error', () => {
    console.log('server error');
})